package cn.edu.flying_birds;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;

/**
 * @PackageName: cn.edu.flying_birds
 * @ClassName: Ground
 * @Description: 地面类
 * @author: RZS
 * @date: 2021/6/21  16:07
 */
public class Ground {
    // 定义地面的坐标信息x， y
    public int x;
    public int y;
    // 定义地面的宽度和高度
    public int width;
    public int height;
    // 定义地面图片对象
    public BufferedImage img;

    public Ground() {
        try {
            init();
        } catch (IOException e) {
            System.out.println("初始化地面失败");
            e.printStackTrace();
        }
    }

    // 初始化方法
    private void init() throws IOException {
        img = ImgUtils.getImg("../img/ground.png");
        width = img.getWidth();
        height = img.getHeight();
        x = 0;
        y = 644 - height;
    }

    /**
     * 地面移动的方法  x
     */
    public void move(){
        // 判断地面尾部是否到达窗口的右边缘
        if(x <= -(width-432)){
            x=0;
        }
        x--;
    }
}
